package job;

import java.util.Stack;

/**
 * @author wq
 */
public class Ali {
    public static void main(String[] args) {
        int nums[]={2,1,3};
        int sum = 0;
        int minNum;
        int minIndex = nums.length;
        int lastIndex = nums.length;
        //每次求出0到上一次最小数的位置之间的最小数
        while (minIndex > 0) {
            minNum = Integer.MAX_VALUE;
            for (int i = 0; i < lastIndex; i++) {
                if (nums[i] < minNum) {
                    minNum = nums[i];
                    minIndex = i;
                }
            }
            sum += (lastIndex - minIndex) * minNum;
            lastIndex = minIndex;
        }
        System.out.println(sum);
    }

}
